package com.zx.flow.api.dict;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.zx.flow.api.util.Util;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

public class FlowDict {

    @Getter
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum Event {
        /**
         * 流程 对外提供的所有 flowStatusChangeEvent
         */
        flowCreate("flowCreate", "流程创建", EventType.flowStatusChangeEvent),
        flowSave("flowSave", "流程保存", EventType.flowStatusChangeEvent),
        flowStart("flowStart", "流程开始", EventType.flowStatusChangeEvent),
        flowCancel("flowCancel", "流程撤销", EventType.flowStatusChangeEvent),
        flowEnd("flowEnd", "流程结束", EventType.flowStatusChangeEvent),
        subFlowStart("subFlowStart", "子流程开始", EventType.flowStatusChangeEvent),
        subFlowEnd("subFlowEnd", "子流程结束", EventType.flowStatusChangeEvent),

        /**
         * node 对外提供的所有 action
         */
        nodeApproved("nodeApproved", "节点通过", EventType.nodeActionEvent),
        nodeRejection("nodeRejection", "节点驳回", EventType.nodeActionEvent),
        nodeSkip("nodeSkip", "节点跳过", EventType.nodeActionEvent),
        nodeTransfer("nodeTransfer", "节点转办", EventType.nodeActionEvent),
        nodeCommunicate("nodeCommunicate", "节点沟通", EventType.nodeActionEvent),
        nodeCommunicateAnswer("nodeCommunicateAnswer", "[回复]节点沟通", EventType.nodeActionEvent),

        nodeAppendOperator("nodeAppendOperator", "增加操作人", EventType.nodeActionEvent),
        nodeRemoveOperator("nodeRemoveOperator", "移除操作人", EventType.nodeActionEvent),

        /**
         * 流程操作过程，触发的内部事件。
         */
        listener("listener", "触发监听", EventType.innerEvent),
        nodeEntry("nodeEntry", "节点进入", EventType.innerEvent),
        nodeAction("nodeAction", "节点操作", EventType.innerEvent),
        nodeFinish("nodeFinish", "节点完成", EventType.innerEvent),
        ;
        private String code;
        private String name;
        private EventType eventType;

        Event(String code, String name, EventType eventType) {
            this.code = code;
            this.name = name;
            this.eventType = eventType;
        }

        public static Event getByCode(String code) {
            for (Event value : Event.values()) {
                if (value.getCode().equals(code)) {
                    return value;
                }
            }
            return null;
        }

        @Override
        public String toString() {
            return Util.getJsonStr2(this);
        }
    }


    /**
     *
     */
    @Getter
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum EventType {
        nodeActionEvent("nodeActionEvent", "节点操作事件"),
        flowStatusChangeEvent("flowStatusChangeEvent", "流程状态变化事件"),

        innerEvent("innerEvent", "内部事件"),
        ;
        private String code;
        private String name;

        EventType(String code, String name) {
            this.code = code;
            this.name = name;
        }

        @Override
        public String toString() {
            return Util.getJsonStr2(this);
        }
    }


    /**
     * 流程状态
     */
    @Getter
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    @Schema(description = "流程状态")
    public enum Status {
        flowNew("flowNew", "流程新建"),
        flowSave("flowSave", "流程保存"),
        flowDoing("flowDoing", "流程中"),
        flowEnd("flowEnd", "流程结束"),
        ;
        @Schema(description = "流程状态", example = "flowNew")
        private String code;

        @Schema(description = "流程状态", example = "流程新建")
        private String name;

        Status(String code, String name) {
            this.code = code;
            this.name = name;
        }

        public static Status getByCode(String code) {
            for (Status status : Status.values()) {
                if (status.code.equals(code)) {
                    return status;
                }
            }
            return null;
        }

        @Override
        public String toString() {
            return Util.getJsonStr2(this);
        }
    }

    /**
     * node流程状态
     */
    @Getter
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum NodeStatus {
        doing("doing", "进行中"),
        finish("finish", "完成"),
        ;
        private String code;
        private String name;

        NodeStatus(String code, String name) {
            this.code = code;
            this.name = name;
        }

        public static NodeStatus getByCode(String code) {
            for (NodeStatus status : NodeStatus.values()) {
                if (status.code.equals(code)) {
                    return status;
                }
            }
            return null;
        }

        @Override
        public String toString() {
            return Util.getJsonStr2(this);
        }
    }

    @Getter
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum OperatorRule {
        system("system", "系统"),
        operator("operator", "操作人员"),
        communicate("communicate", "沟通人员"),
        ;
        private String code;
        private String name;

        OperatorRule(String code, String name) {
            this.code = code;
            this.name = name;
        }

        @Override
        public String toString() {
            return Util.getJsonStr2(this);
        }
    }

    /**
     * 操作类型
     */
    @Getter
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum OperationType {
        all("all", "全部操作"),
        anyone("anyone", "任意一人");
        private String code;
        private String name;

        OperationType(String code, String name) {
            this.code = code;
            this.name = name;
        }

        @Override
        public String toString() {
            return Util.getJsonStr2(this);
        }
    }

    /**
     * 操作人获取类型
     */
    @Getter
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum OperatorGetType {
        http("http", "调用http获取"),
        array("array", "从列表获取");
        private String code;
        private String name;

        OperatorGetType(String code, String name) {
            this.code = code;
            this.name = name;
        }

        @Override
        public String toString() {
            return Util.getJsonStr2(this);
        }
    }

    @Getter
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum ListenerType {
        wc("wc", "企微"),
        dd("dd", "钉钉"),
        fs("fs", "飞书"),

        mq("mq", "mq"),
        sms("sms", "短信"),
        http("http", "http"),
        ;
        private String code;
        private String name;

        ListenerType(String code, String name) {
            this.code = code;
            this.name = name;
        }

        @Override
        public String toString() {
            return Util.getJsonStr2(this);
        }
    }

    @Getter
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum ExecuteStatus {
        success("success", "成功"),
        failed("failed", "失败"),
        exception("exception", "发生异常"),
        invalid("invalid", "无效"),
        ;
        private String code;
        private String name;

        ExecuteStatus(String code, String name) {
            this.code = code;
            this.name = name;
        }

        @Override
        public String toString() {
            return Util.getJsonStr2(this);
        }
    }

    @Getter
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum StorageType {
        mock("localFile", "本地文件"),
        db("db", "数据库"),
        redis("redis", "redis"),
        elasticsearch("elasticsearch", "elasticsearch"),
        http("http", "远程接口"),
        ;
        private String code;
        private String name;

        StorageType(String code, String name) {
            this.code = code;
            this.name = name;
        }

        @Override
        public String toString() {
            return Util.getJsonStr2(this);
        }
    }


}
